<template>
    <div class="app-container">
        <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        v-show="showSearch"
        label-width="0px"
      >
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="" prop="serialCode">
          <el-input
            v-model="queryParams.serialCode"
            placeholder="应用系统上线运行申请单编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="ywProjectName">
          <el-input
            v-model="queryParams.ywProjectName"
            placeholder="系统名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="" prop="projectCode">
          <el-input
            v-model="queryParams.projectCode"
            placeholder="系统编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        </el-col>
        <el-col :span="6">
            <el-form-item label="" prop="ywDept">
              <el-select v-model="queryParams.ywDept" size="small" placeholder="业务主管部门" style="width:100%" clearable>
                <el-option
                  v-for="item in deptOptions"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptName">
                </el-option>
              </el-select>
            </el-form-item>
        </el-col>
        
        <el-col :span="6">
          <el-form-item label="" prop="impCompany">
            <el-select v-model="queryParams.impCompany" size="small" style="width:100%" clearable placeholder="实施单位">
              <el-option v-for="(item,index) in deptOptions"
                :key="index"
                :label="item.deptName"
                  :value="item.deptName">
                  </el-option>
               </el-select>
             </el-form-item>
            </el-col>
        <el-col :span="6">
            <el-form-item label="" prop="approvalStatus">
              <el-select v-model="queryParams.approvalStatus" size="small" placeholder="申请状态" style="width:100%" clearable>
                <el-option
                  v-for="(item,index) in TaskNameArr"
                  :key="index"
                  :label="item"
                  :value="item"
                />
              </el-select>
            </el-form-item>
        </el-col>
        
        <el-col :span="6">
          <el-form-item label="">
            <el-date-picker
            size="small"
              v-model="dateRange"
              style="width: 100%"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="申请开始日期"
              end-placeholder="申请结束日期"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="">
          <el-date-picker
          size="small"
            v-model="createTime"
            style="width: 100%"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="daterange"
            range-separator="-"
            start-placeholder="创建开始日期"
            end-placeholder="创建结束日期"
            :default-time="['00:00:00', '23:59:59']"
          ></el-date-picker>
        </el-form-item>
      </el-col>
      </el-row>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            :disabled="multiple"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table ref="multipleTable" v-loading="loading" :data="leaveFinishedList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column type="index" width="55" fixed label="序号" align="center" />
        <el-table-column label="应用系统上线运行申请单编号" fixed align="center" prop="serialCode" width="170" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
          <el-link type="primary" @click="handleFlowRecord(scope.row)">{{scope.row.serialCode}}</el-link>
        </template>
        </el-table-column>
        <el-table-column label="系统名称" fixed align="center" width="160" prop="ywProjectName"></el-table-column> 
        <el-table-column label="系统编号" align="center" width="160" prop="projectCode">
        </el-table-column>
        <el-table-column label="业务主管部门" align="center" prop="ywDept">
        </el-table-column>
        <el-table-column label="业务联系人" align="center" width="160" prop="ywPeople"></el-table-column> 
        <el-table-column label="实施单位" align="center" width="160" prop="impCompany"></el-table-column>
        <el-table-column label="实施单位联系人" align="center" width="160" prop="impPeople"></el-table-column>
         <el-table-column label="申请状态" align="center" prop="approvalStatus" >
          <!-- <template slot-scope="scope">
            <dict-tag :options="dict.type.ration_status" :value="scope.row.approvalStatus"/>
          </template> -->
        </el-table-column>
        <el-table-column label="申请日期" sortable align="center" prop="applyForTime" width="180" />
        <el-table-column label="创建日期" sortable align="center" prop="createTime" width="150" />
        <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="100">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleFlowRecord(scope.row)"
            >查看详情</el-button>
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-tickets"
              @click="handleRevoke(scope.row)"
              v-hasPermi="['workflow:process:revoke']"
            >撤回
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </template>
  
  <script>
  import { officeFinishedList,deptListAll,getTaskName } from '@/api/administeration/askForLeave.js';
  import { revokeProcess } from "@/api/workflow/finished";
import { elecFormSysApplyExcel } from "@/api/message/virtualMachine.js"
  export default {
    name: "onlinefinished",
    dicts:['vacetsu_status','ration_status'],
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 所属部门下拉框
        deptOptions: [],
        TaskNameArr:[],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 已办任务列表数据
        leaveFinishedList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        dateRange: [],
        createTime:[],
        properties:[],
        impCompanyList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          serialCode: null,
          ywProjectName: null,
          projectCode: null,
          ywDept: null,
          impCompany: null,
          approvalStatus: null, 
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
        Code:'CODE_XTSQ'
      };
    },
     // 利用activated函数来进行函数调用，这样可以保证每次进入界面都能刷新界面内容
    activated () {
      this.getList()
    },
    created() {
      this.getList()
    },
    methods: {
      // 下拉状态
      async getTaskNameArr() {
        const deptres = await getTaskName({
          keyword:'应用系统上线运行'
        })
        this.TaskNameArr = deptres.data
      },
      // 下拉部门
       async getDeptListAll() {
        const deptres = await deptListAll()
        this.deptOptions = deptres.data
       },
      /** 查询流程定义列表 */
      getList() {
        this.loading = true;
        let obj = {}
        if (this.dateRange != null && this.dateRange.length>0) {
          obj = {
            applyForStartDate:this.dateRange[0],
           applyForEndDate:this.dateRange[1]
          }
        }
        let createObj = {}
        if (this.createTime != null && this.createTime.length>0 ) {
          createObj = {
            createStartDate:this.createTime[0],
           createEndDate:this.createTime[1]
          }
        }
        officeFinishedList({ ...this.queryParams,...obj,...createObj },this.Code).then(response => {
          this.leaveFinishedList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
         this.getTaskNameArr()
        this.getDeptListAll()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.createTime = [],
        this.resetFormData("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "新增流程定义";
      },
      /** 流程流转记录 */
      handleFlowRecord(row){
        this.$router.push({
          path: '/workflow/process/messagedetail/' + row.procInstId,
          query: {
            processed: false
          }
        })
      },
      /** 撤回任务 */
      // handleRevoke(row) {
      //   const params = {
      //     procInsId: row.procInsId,
      //     taskId: row.taskId
      //   };
      //   revokeProcess(params).then(res => {
      //     this.$modal.msgSuccess(res.msg);
      //     this.getList();
      //   });
      // },
      /** 导出按钮操作 */
      // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.serialCode);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      console.log(this.ids);
      let list = [];
      if(this.ids.length > 0){
        this.ids.forEach(ele => {
         let  obj = this.leaveFinishedList.find(item => item.serialCode==ele);
          list.push(obj)
        });
        console.log(list,"88888888888888");
        elecFormSysApplyExcel(list).then(res=>{
          if(res){
          const blob = new Blob([res],{type: 'application/vnd.ms-excel'});
          const fileName ="应用系统上线申请表（已办）.xlsx";
          if ("download" in document.createElement("a")) {
            // 非IE下载
            const elink = document.createElement("a");
            elink.download = fileName;
            elink.style.display = "none";
            elink.href = URL.createObjectURL(blob);
            document.body.appendChild(elink);
            elink.click();
            URL.revokeObjectURL(elink.href); // 释放URL 对象
            document.body.removeChild(elink);
          } else {
            // IE10+下载
            navigator.msSaveBlob(blob, fileName);
          }
            this.$refs.multipleTable.clearSelection();
          }

       })

      }
    }
    }
  };
  </script>
  